//
//  SceneCollectionViewCell.m
//  TodatPlay
//
//  Created by dllo on 16/9/6.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "SceneCollectionViewCell.h"
#import "SceneTableViewCell.h"
#import "SDAutoLayout.h"
#import "TAMacro.h"

#define kTableViewSceneCellReuse @"sceneReuse"
@interface SceneCollectionViewCell ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *sceneTableView;


@end

@implementation SceneCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self configTableView];
}
- (void)configTableView {
    self.sceneTableView.delegate = self;
    self.sceneTableView.dataSource = self;
    [self.sceneTableView registerClass:[SceneTableViewCell class] forCellReuseIdentifier:kTableViewSceneCellReuse];
    self.sceneTableView.backgroundColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    
}
#pragma mark - datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SceneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewSceneCellReuse];
    
    return cell;
}
#pragma mark - 返回cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:self.sceneTableView];
}
#pragma mark - 反回头视图和头视图的高度
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headVeiw = [UIView new];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [headVeiw addSubview:button];
    [button setTitle:@"我要发记录" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    [button addTarget:self action:@selector(handleButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    button.layer.borderWidth = 1;
    button.layer.borderColor = [UIColor blackColor].CGColor;
    button.layer.masksToBounds = YES;

    headVeiw.sd_layout
    .leftEqualToView(self.sceneTableView)
    .topEqualToView(self.sceneTableView)
    .rightEqualToView(self.sceneTableView);
    button.sd_layout
    .centerXEqualToView(headVeiw)
    .centerYEqualToView(headVeiw)
    .heightIs(30)
    .widthIs(SCREEN_WIDTH / 2.0);
    
    return headVeiw;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60;
}


#pragma mark - 我要发记录按钮方法
- (void)handleButton:(UIButton *)btn {
    NSLog(@"点击了发送记录");
}


#pragma mark - 不让区头视图滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.sceneTableView)
    {
        CGFloat sectionHeaderHeight = 60;
        if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}









@end

